//
//  LeaderboardFromView.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/11.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "LeaderboardFromView.h"

@implementation LeaderboardFromView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self addSubview:self.headView];
        [self addSubview:self.userName];
        [self.headView addSubview:self.userHead];
        [self addSubview:self.gradeView];
        [self.gradeView addSubview:self.gradeBtn];
        UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tbg"]];
        [self setBackgroundColor:color];
        self.contentMode = UIViewContentModeScaleAspectFit;
        [self showLeaderboardView];
    }
    return self;
}

- (void)showLeaderboardView
{
    _headView.sd_layout
    .topSpaceToView(self,kHeightScale(64))
    .leftSpaceToView(self,kWidthScale(160))
    .widthIs(kWidthScale(55))
    .heightIs(kHeightScale(55));
    
    _userHead.sd_layout
    .topSpaceToView(self.headView,kHeightScale(3))
    .leftSpaceToView(self.headView,kWidthScale(3))
    .rightSpaceToView(self.headView,kWidthScale(3))
    .bottomSpaceToView(self.headView,kHeightScale(3));
    
    _gradeView.sd_layout
    .bottomEqualToView(self.headView)
    .rightSpaceToView(self,kWidthScale(144))
    .widthIs(kWidthScale(24))
    .heightIs(kHeightScale(24));
    
    _gradeBtn.sd_layout
    .topSpaceToView(self.gradeView,kHeightScale(4))
    .leftSpaceToView(self.gradeView,kWidthScale(4))
    .rightSpaceToView(self.gradeView,kWidthScale(4))
    .bottomSpaceToView(self.gradeView,kHeightScale(4));
    
    _userName.sd_layout
    .topSpaceToView(self.headView,kHeightScale(6))
    .centerXEqualToView(self.headView)
    .autoHeightRatio(0);
    [_userName setSingleLineAutoResizeWithMaxWidth:kWidthScale(100)];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (UIView *)headView
{
    if (!_headView)
    {
        _headView = [[UIView alloc] init];
        _headView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.4];
        _headView.layer.cornerRadius = kWidthScale(26);
        _headView.layer.masksToBounds = YES;
    }
    return _headView;
}

- (UIButton *)userHead
{
    if (!_userHead)
    {
        _userHead = [UIButton buttonWithType:UIButtonTypeCustom];
        _userHead.layer.cornerRadius = kWidthScale(26);
        _userHead.layer.masksToBounds = YES;
        [_userHead setBackgroundImage:[UIImage imageNamed:@"toixiang"] forState:0];
        _userHead.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.4];
    }
    return _userHead;
}

- (UIButton *)gradeBtn
{
    if (!_gradeBtn)
    {
        _gradeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_gradeBtn setTitle:@"12" forState:0];
        [_gradeBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:0];
        _gradeBtn.titleLabel.font = [UIFont systemFontOfSize:kHeightScale(13)];
        _gradeBtn.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];
        _gradeBtn.layer.cornerRadius = kHeightScale(8);
        _gradeBtn.layer.masksToBounds = YES;
    }
    return _gradeBtn;
}

- (UIView *)gradeView
{
    if (!_gradeView)
    {
        _gradeView = [[UIView alloc] init];
        _gradeView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.4];
        _gradeView.layer.cornerRadius = kHeightScale(11);
        _gradeView.layer.masksToBounds = YES;
    }
    return _gradeView;
}

- (UILabel *)userName
{
    if (!_userName)
    {
        _userName = [[UILabel alloc] init];
        _userName.text = @"迪丽热巴";
        _userName.textColor = [UIColor whiteColor];
        _userName.textAlignment = NSTextAlignmentCenter;
        _userName.font = [UIFont systemFontOfSize:kHeightScale(17)];
        [_userName updateLayout];
    }
    return _userName;
}

@end
